/*
 * io_auxillary.c
 *
 *  Created on: Mar 10, 2012
 *      Author: User
 */

#include <pthread.h>
#include "io_auxillary.h"
#include "process.h"
#include "pcb.h"

void run_auxiliary(void* ptr){
	//printf("I'm in the run auxiliary method.\n");
	int* flag = (int*)ptr;
	while(1) {
		for(int i = 0; i < 200000; i++);
		if(*flag == 1){
			printf("changed value of flag.\n");
			*flag = 0;
		}
	}
}

int test_auxillary(void){
	printf("I'm in the test_auxillary method.\n");
	pcb* proc = pcb_new(0);
	proc->state = BLOCKED;

	pcb* p = pcb_new(1);
	p->state = BLOCKED;

	Queue q = CreateQueue(100);
	Enqueue(proc, q);
	Enqueue(p, q);

	printf("Is queue empty? %i\n", IsEmpty(q));

	pthread_t thread;

	printf("I'm inside the loop.Really.\n");
//	int tn = pthread_create(&thread, NULL, run_auxillary, (void*)aux);
	int num = 0;

	return 1;
}

Queue populate_test_queue(Queue q){
	pcb* proc = pcb_new(0);
	proc->state = BLOCKED;
	pcb* p = pcb_new(1);
	proc->state = BLOCKED;

	//test_process_print(proc);
	Enqueue(proc, q);
	Enqueue(p, q);

	return q;
}

